<?php

namespace app\common\model;

use app\common\validate\CommentVlidate;
use think\Model;
use think\model\concern\SoftDelete;

class Comment extends Model
{
    // 软删除
    use SoftDelete;

    // 关联文章模型
    public function article()
    {
        return $this->belongsTo('article', 'article_id', 'id');
    }

    // 关联会员模型
    public function member()
    {
        return $this->belongsTo('member', 'member_id', 'id');
    }


    // 提交评论
    public function comment($data)
    {
        $validate = new CommentVlidate();
        if (!$validate->scene('comment')->check($data)){
            return $validate->getError();
        }
        $result = $this->allowField(true)->save($data);
        if ($result){
            return 1;
        }else{
            return '评论失败';
        }
    }
}
